function out= frameDec(signal, level, HD)
%This program performs 1D framelet transform. 
%Parameters:
%signal : the input signal. Type : matrix(1,N)
%level : the level of decomposition. Type : int
%HD : the destruction filter. Type : cell
%output:
%out : the transform coefficients. Type : cell
nfilters = numel(HD);
out = [];
lenSignal = length(signal);

while level>0
    lenFilter = length(HD{1});
    extSignal = [signal(lenSignal - (lenFilter-3)/2 : lenSignal) signal signal(1:(lenFilter-1)/2)];
    for k = 1 : nfilters
        filters(k,:) = HD{k};
    end
    out1 = conv2( extSignal, filters );
    temp = out1( :,lenFilter : lenFilter-1+lenSignal);
    temp2 = reshape(temp',[1,numel(temp)]);
    HD = doubleFilter(HD);
    if ~isempty(out)
        out(1 : lenSignal) = [];
    end
    out = [temp2 out];
    signal = temp2(1:lenSignal);
    level = level -1;
    clear filters;
end
end
